package com.example.zn.controller;

import com.example.zn.dto.Result;
import com.example.zn.entity.Category;
import com.example.zn.entity.Product;
import com.example.zn.service.CategoryService;
import com.example.zn.service.impl.ProductServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

@Tag(name = "分类管理",description = "分类相关访问操作，包含：新增，检索，修改，删除等")
@CrossOrigin
@RestController
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

@Operation(summary = "分类列表对象",description = "查询所有分类信息，为上传商品时做相关联使用")
    @GetMapping("/category/listAll")
    public Result queryAll(){
        List<Category> list = categoryService.list();
        return Result.ok().setData(list);
    }
    @Operation(summary = "根据id修改商品",description = "需要提供商品的id")
    @PostMapping("/category/update")
    public Result modify(@Parameter(description = "商品对象") @RequestBody Category category){
        if (categoryService.updateById(category)){
            return Result.ok().setMsg("修改成功").setData(category);

        }
        return Result.fail().setMsg("修改失败");
    }



}
